package com.jdcjk.project.setting.presenter;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.jdcjk.base.presenter.BasePresenter;
import com.jdcjk.project.account.model.entity.Result;
import com.jdcjk.project.setting.model.SettingModel;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by Administrator on 2016/12/16 0016.
 */

public class SettingPresenter extends BasePresenter<SettingModel> {

    public SettingPresenter(Context context) {
        super(context);
    }

    @Override
    public SettingModel bindModel() {
        return new SettingModel(getContext());
    }

    /**
     * 修改用户信息请求
     *
     * @param url                请求地址
     * @param account            账号
     * @param username           名称
     * @param email              邮箱
     * @param address            地址
     * @param onUIThreadListener 主线程回调
     */
    public void updateUserInfo(String url, String account, String username, String email, String address, final OnUIThreadListener<Result> onUIThreadListener) {
        getModel().updateUserInfo(url, account, username, email, address, new StringCallback() {
            @Override
            public void onAfter(int id) {
                onUIThreadListener.onAfter(id);
            }

            @Override
            public void onBefore(Request request, int id) {
                onUIThreadListener.onBefore(request, id);
            }

            @Override
            public void onError(Call call, Exception e, int i) {
                onUIThreadListener.onError(call, e, i);
            }

            @Override
            public void onResponse(String s, int i) {
                Gson json = new Gson();
                Result updateUserInfoResult = json.fromJson(s, Result.class);
                onUIThreadListener.onResponse(updateUserInfoResult);
            }
        });
    }
}
